
//
//	cove.events.Event - 2011 May 16th
//
//	The Event class is used as the base class for the creation of Event objects, which are passed
//	as parameters to event listeners when an event occurs. 
//
//-------------------------------------------------------------------------------------------------

var Event = cove.events.Event = Class.extend({
	
	_jsDefaultCall: false,
	_defaultPrevented: false,
	_immediatePropagation: true,
	_propagation: true,
	
	init: function(type, bubbles, cancelable) {
		this._type = type;
		this._bubbles = typeof bubbles == 'boolean' ? bubbles : false;
		this._cancelable = typeof cancelable == 'boolean' ? cancelable : false;
	},
	
	
//	Public properties
//-------------------------------------------------------------------------------------------------
	
	// Indicates whether an event is a bubbling event.
	get bubbles() { return this._bubbles; },
	
	// Indicates whether the behavior associated with the event can be prevented.
	get cancelable() { return this._cancelable; },
	
	// The object that is actively processing the Event object with an event listener.
	get currentTarget() { return this._currentTarget; },
	
	// The current phase in the event flow.
	get eventPhase() { return null; },
	
	// The event target.
	get target() { return this._target; },
	
	// The type of event.
	get type() { return this._type; },
	

//	Public methods
//-------------------------------------------------------------------------------------------------

	// Duplicates an instance of an Event subclass.
	clone: function() {
		return new Event(this._type, this._bubbles, this._cancelable);
	},
	
	// A utility function for implementing the toString() method in your custom Event class.
	formatToString: function(className) {
		var ret = '[' + className;
		for(var i = 1, len = arguments.length; i < len; i++) {
			ret += ' ' + arguments[i] + '=';
			if(typeof this[arguments[i]] == 'string')
				ret += '"' + this[arguments[i]] + '"';
			else
				ret += this[arguments[i]];
		}
		return ret + ']';
	},
	
	// Checks whether preventDefault() has been called on the event.
	isDefaultPrevented: function() {
		return this._defaultPrevented;
	},
	
	// Cancels an event's default behavior if that behavior can be canceled.
	preventDefault: function() {
		this._defaultPrevented = true;
		//...
	},
	
	// Prevents processing of any event listeners in the current node and any subsequent nodes in
	// the event flow.
	stopImmediatePropagation: function() {
		this._immediatePropagation = false;
		this._propagation = false;
	},
	
	// Prevents processing of any event listeners in nodes subsequent to the current node in the
	// event flow.
	stopPropagation: function() {
		this._propagation = false;
	},
	
	// Returns a string containing all the properties of the Event object.
	toString: function() {
		return this.formatToString('Event', 'type', 'bubbles', 'cancelable');
	}
	
});


//	Event types
//-------------------------------------------------------------------------------------------------

Event.ACTIVATE = 'activate';
Event.ADDED = 'added';
Event.ADDED_TO_STAGE = 'addedToStage';
Event.CANCEL = 'cancel';
Event.CHANGE = 'change';
Event.CLOSE = 'close';
Event.COMPLETE = 'complete';
Event.CONNECT = 'connect';
Event.DEACTIVATE = 'deactivate';
Event.ENTER_FRAME = 'enterFrame';
Event.FULLSCREEN = 'fullScreen';
Event.HTML_BOUNDS_CHANGE = 'htmlBoundsChange';
Event.HTML_DOM_INITIALIZE = 'htmlDOMInitialize';
Event.HTML_RENDER = 'htmlRender';
Event.ID3 = 'id3';
Event.INIT = 'init';
Event.MOUSE_LEAVE = 'mouseLeave';
Event.OPEN = 'open';
Event.REMOVED = 'removed';
Event.REMOVED_FROM_STAGE = 'removedFromStage';
Event.RENDER = 'render';
Event.RESIZE = 'resize';
Event.SCROLL = 'scroll';
Event.SELECT = 'select';
Event.SOUND_COMPLETE = 'soundComplete';
Event.TAB_CHILDREN_CHANGE = 'tabChildrenChange';
Event.TAB_ENABLED_CHANGE = 'tabEnabledChange';
Event.TAB_INDEX_CHANGE = 'tabIndexChange';
Event.UNLOAD = 'unload';
